package com.chorye.blog.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Company: 北京根网科技有限公司
 * @Author JiangYy
 * @Title: TestController
 * @Description: TODO
 * @Date 2018/12/27 17:31
 */
@Controller
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/md")
    public String md() {
        return "/md";
    }

    @RequestMapping("/file")
    @ResponseBody
    public void upload(HttpServletResponse response,  @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
        if (file.isEmpty()) {
            response.getWriter().write( "{\"success\": 0, \"message\":\"上传失败\",\"url\":\"" + "111" + "\"}" );
        }
        String fileName = file.getOriginalFilename();
        int size = (int) file.getSize();
        System.out.println(fileName + "-->" + size);
        response.getWriter().write( "{\"success\": 1, \"message\":\"上传成功\",\"url\":\"" + "222" + "\"}" );
    }
}
